/*
 *  MainComponent.cpp
 *  mediTock
 *
 *  Created by tjmitche on 02/04/2009.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */

#include "tevolutionComponent.h"
#include "AlgorithmTab.h"
#include "FitnessTab.h"
#include "ResultsTab.h"
#include "RunTab.h"

//////////////
TevolutionTabsComponent::TevolutionTabsComponent () : TabbedComponent (TabbedButtonBar::TabsAtTop)
{
	addTab (T("Algorithm"),			getRandomBrightColour(), new AlgorithmTabComponent(), true);
	addTab (T("Fitness"),			getRandomBrightColour(), new FitnessTabComponent(), true);
	addTab (T("Results"),			getRandomBrightColour(), new ResultsTabComponent(), true);
	addTab (T("Run"),				getRandomBrightColour(), new RunTabComponent(), true);
}

TevolutionTabsComponent::~TevolutionTabsComponent()
{
	
}

void TevolutionTabsComponent::buttonClicked (Button* button)
{
	BubbleMessageComponent* bmc = new BubbleMessageComponent();
	
	if (Desktop::canUseSemiTransparentWindows())
	{
		bmc->setAlwaysOnTop (true);
		bmc->addToDesktop (0);
	}
	else
	{
		addChildComponent (bmc);
	}
	
	bmc->showAt (button, T("This is a demo of the BubbleMessageComponent, which lets you pop up a message pointing at a component or somewhere on the screen.\n\nThe message bubbles will disappear after a timeout period, or when the mouse is clicked."),
				 2000, true, true);
}

const Colour TevolutionTabsComponent::getRandomBrightColour()
{
	return Colour (Random::getSystemRandom().nextFloat(), 0.1f, 0.97f, 1.0f);
}

//==============================================================================

TevolutionComponent::TevolutionComponent ()
{
	setName (T("Widgets"));
	
	addAndMakeVisible (tabs = new TevolutionTabsComponent ());
	
	//==============================================================================
	
	enableButton = new ToggleButton (T("enable/disable components"));
	addAndMakeVisible (enableButton);
	enableButton->setBounds (230, 10, 180, 24);
	enableButton->setTooltip (T("toggle button"));
	enableButton->setToggleState (true, false);
	enableButton->addButtonListener (this);
	
}

TevolutionComponent::~TevolutionComponent ()
{
	// Be sure to destroy any objects you've created using 'new' here. If your objects
	// are on the stack (i.e. they were created without pointers or the 'new' operator,
	// then they die automatically. If you've created them
	// manually on the heap (for example, if you've got a pointer and you've created a new
	// object for it) then it must be deleted.
	
	// However, juce has a nice neat function that will destroy all Components that have
	// been added to a Component...
	
	deleteAllChildren();   // This will remove all the contained components, and delete
	// the objects for you.
}

//==============================================================================
void TevolutionComponent::resized ()
{

	tabs->setBounds (10, 40, getWidth() - 20, getHeight() - 50);
}

void TevolutionComponent::paint (Graphics& g)
{
	// This does any drawing required on this Component's face. You can simply
	// call functions on the provided Graphics object - although you may want to
	// make use of 'getWidth()' and 'getHeight()' (members of this Component) to
	// make sure you're drawing in the right place!
	
}


void TevolutionComponent::buttonClicked (Button* button)
{
	if (button == enableButton)
	{
		const bool enabled = enableButton->getToggleState();
		
		tabs->setEnabled (enabled);
	}
}
